using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Iacym.Entities;

namespace Iacym.Repository.Mapping
{
    public class TELEFONOMap : EntityTypeConfiguration<TELEFONO>
    {
        public TELEFONOMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.NumeroTelefonico)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("TELEFONOS");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Dni).HasColumnName("Dni");
            this.Property(t => t.NumeroTelefonico).HasColumnName("NumeroTelefonico");
            this.Property(t => t.LineaId).HasColumnName("LineaId");

            // Relationships
            this.HasOptional(t => t.LINEA_TELEFONICA)
                .WithMany(t => t.TELEFONOS)
                .HasForeignKey(d => d.LineaId);
            this.HasRequired(t => t.PERSONA)
                .WithMany(t => t.TELEFONOS)
                .HasForeignKey(d => d.Dni);

        }
    }
}
